home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group93c.txt / 000012_icon-group-sender _Tue Jul 20 11:00:24 1993.msg < prev    next >
Internet Message Format  |  1994-02-02  |  1KB

  1. Received: by cheltenham.cs.arizona.edu; Tue, 20 Jul 1993 08:10:00 MST
  2. Date: Tue, 20 Jul 93 11:00:24 EDT
  3. From: Paul_Abrahams@MTS.cc.Wayne.edu
  4. To: icon-group@cs.arizona.edu
  5. Message-Id: <705767@MTS.cc.Wayne.edu>
  6. Subject: Mystery about "every"
  7. Status: R
  8. Errors-To: icon-group-errors@cs.arizona.edu
  9.  
  10.  
  11. I thought I understood how "every" works -- at least when I check
  12. everything out in the book -- but I've come across a program whose
  13. behavior leaves me utterly baffled (this under OS/2 V8.8 Icon).  Consider
  14. the following example, derived from the program where the problem
  15. appeared:
  16.  
  17. procedure main()
  18.    local retval, c, s
  19.    s := "123"
  20.    retval := 0
  21.    every  c := !s do
  22.       retval :=  8 * retval + ord(c) - ord("0")
  23.    write("Octal output is ", retval)
  24. end
  25.  
  26. This program produced the output 83, as expected.  But I then replaced
  27. the "every" statement by the following one, which I thought to be more
  28. elegant:
  29.  
  30.    every retval :=  8 * retval + ord(!s) - ord("0")
  31.  
  32. Now the output of the program is 3 (the last digit), not 83.
  33.  
  34. Can anyone explain to me what's going on?
  35.  
  36. Thanks.
  37.  
  38. Paul Abrahams
  39. Reply-To: abrahams@acm.org
  40.